/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.open.api.core.service.processor.base.pre;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.Assert;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import info.peigen.hotpot.component.open.api.core.enums.OpenApiResultCode;
import info.peigen.hotpot.component.open.api.core.service.processor.base.AbstractOpenApiServiceProcessor;
import info.peigen.hotpot.component.open.api.facade.order.OpenApiOrder;
import info.peigen.hotpot.component.open.api.facade.processor.base.OpenApiProcessor;
import info.peigen.hotpot.component.open.api.facade.processor.base.OpenApiProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(OpenApiSessionVerifyProcessor)</b>
 *
 * @author LiHai
 * @version 1.0.0
 * @since 2022/8/16
 */
@SuppressWarnings("rawtypes")
@Component
public class OpenApiSessionVerifyProcessor extends AbstractOpenApiServiceProcessor implements OpenApiProcessor {

    @Override
    public Integer level() {
        return 3;
    }

    @Override
    public void execute(OpenApiProcessorServiceContext serviceContext) {
        OpenApiOrder order = serviceContext.getOrder();
        Assert.isTrue(openApiAuthVerifyIgnoreConfiguration.isIgnoreApiCodes(order.getApiCode()) || StpUtil.isLogin(),
                () -> new BusinessException(OpenApiResultCode.SESSION_EXPIRED, "登录失效,token=" + StpUtil.getTokenValue()));
    }
}